import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import kvStoreUtil from '../util/kvStore/kvStoreUtil';
import log from '../util/logutil';
import deviceInfo from '@ohos.deviceInfo';
import fs from '@ohos.file.fs';

export default class EntryAbility extends UIAbility {
  onCreate(want, launchParam) {
    //初始化全局单例 kvStoreUtil
    kvStoreUtil.init(this.context)
  }

  onDestroy() {
   kvStoreUtil.getInstance().closed();
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    let context = this.context;
    let pathDir = context.filesDir;
    let dirPath = pathDir + "/schemes";
    fs.mkdir(dirPath).then(() => {
      console.info("mkdir succeed");
    }).catch((err) => {
      console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
    });
    windowStage.loadContent('pages/Index', (err, data) => {
      if (err.code) {
        return;
      }
    });
  }

  onWindowStageDestroy() {
    // Main window is destroyed, release UI related resources
  }

  onForeground() {
    // Ability has brought to foreground
  }

  onBackground() {
    // Ability has back to background
  }
}
